package com.gxc.mapper;

import com.gxc.entity.User;
import java.util.List;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * UserMapper.
 *
 * @author 宫新程
 * @since 2018/12/28 11:06 AM
 */
@Mapper
public interface UserMapper {

  /** 分页查询User列表. */
  @Select("select * from user")
  List<User> list(@Param("pageNum") Integer pageNum, @Param("pageSize") Integer pageSize);

  /** 批量保存. */
  @Insert(
      "<script>"
          + "insert into user(username, password, age, role, login_date) "
          + "values <foreach item = 'param' index = 'index' collection='params' separator=','> "
          + "(#{param.username}, #{param.password}, #{param.age}, #{param.role}, #{param.loginDate}) "
          + "</foreach>"
          + "</script>")
  @Options(useGeneratedKeys = true, keyColumn = "id")
  void saveAll(@Param("params") List<User> userList);
}
